package com.device.operating.utils;

import java.util.ArrayList;
import java.util.List;

public class VlanStr {
	public static String[] getvlan(int pppvlan){//一般是ONU的，单个VLAN
		String[] vlan=new String[4];//s[0]-pppoe,s[1]-iptv,s[2]-预留vlan,s[3]-voipvlan
		int svlan=pppvlan;
		vlan[0]=pppvlan+"";
		if(svlan>1000&&svlan<2000){
			vlan[1]=svlan+1000+"";//iptv
			vlan[2]=svlan+2000+"";//ylvlan
			vlan[3]=svlan+1500+"";//voipvlan
		}else{
			vlan[1]=svlan-200+"";
			vlan[2]=svlan-600+"";
			vlan[3]=svlan-400+"";
		}
		return vlan;
	}
	
	public static String[] getvlans(String pppvlan){//一般是OLT的，是一段，例如1001-1020
		String[] vlan=new String[4];//s[0]-pppoe,s[1]-iptv,s[2]-预留vlan,s[3]-voipvlan
		String[] pppvlans=pppvlan.split("-");
		if(pppvlans.length==1)
			return null;
		
		int[] svlan=new int[2];
		svlan[0]=new Integer(pppvlans[0]).intValue();
		svlan[1]=new Integer(pppvlans[1]).intValue();
		vlan[0]=pppvlans[0]+"-"+pppvlans[1];
		if(svlan[0]>1000&&svlan[0]<2000){
			vlan[1]=svlan[0]+1000+"-"+(svlan[1]+1000);//iptv
			vlan[2]=svlan[0]+2000+"-"+(svlan[1]+2000);//ylvlan
			vlan[3]=svlan[0]+1500+"-"+(svlan[1]+1500);//voipvlan
		}else{
			vlan[1]=svlan[0]-200+"-"+(svlan[1]-200);
			vlan[2]=svlan[0]-600+"-"+(svlan[1]-600);
			vlan[3]=svlan[0]-400+"-"+(svlan[1]-400);
		}
		return vlan;
	}
	
	public static List<String[]> getonuvlans(int vlanbegin,int ponnum,int ponc){//ponc:几个PON口占一个VLAN
		List<String[]> list=new ArrayList<>();
		int t=0;
		while(t<ponnum){
			for(int i=0;i<ponc;i++){
				String[] str=VlanStr.getvlan(vlanbegin);
				list.add(str);
				t++;
			}
			if(vlanbegin>1000&&vlanbegin<2000)
				vlanbegin++;
			else
				vlanbegin--;	
		}
		return list;
	}
	
	public static List<String[]> getcunonuvlans(int vlanbegin,int ponnum,int ponc,int typenum){//ponc:几个PON口占一个VLAN//typenum++OR--
		List<String[]> list=new ArrayList<>();
		int t=0;
		while(t<ponnum){
			for(int i=0;i<ponc;i++){
				String[] str=VlanStr.getvlan(vlanbegin);
				list.add(str);
				t++;
			}
			vlanbegin+=typenum;
		}
		return list;
	}
	
	public static int Honunextcvlan(String portnum,String dvfirm) {
		// TODO Auto-generated method stub
		int[] ivall={1001,1029,1257,1385};
		int port=new Integer(portnum).intValue();
		if(dvfirm.equals("中兴"))
			return ivall[(port-1)%4];
		else
			return ivall[port%4];
	}
	
	public static String[] getothervlans(String pppvlan){
		String[] vlan=new String[]{"","","",""};
		String[] ppp=pppvlan.split(",");
		for(int i=0;i<ppp.length;i++){
			int[] svlan=new int[2];
			svlan[0]=Integer.valueOf(ppp[i].split("-")[0]);
			svlan[1]=Integer.valueOf(ppp[i].split("-")[1]);
			vlan[0]=vlan[0]+svlan[0]+"-"+svlan[1]+",";
			
			if(svlan[0]>1000&&svlan[0]<2000){
				vlan[1]=vlan[1]+((svlan[0]+1000)+"-"+(svlan[1]+1000))+",";//iptv
				vlan[2]=vlan[2]+((svlan[0]+2000)+"-"+(svlan[1]+2000))+",";//ylvlan
				vlan[3]=vlan[3]+((svlan[0]+1500)+"-"+(svlan[1]+1500))+",";//voipvlan
			}else{
				vlan[1]=vlan[1]+((svlan[0]-200)+"-"+(svlan[1]-200))+",";
				vlan[2]=vlan[2]+((svlan[0]-600)+"-"+(svlan[1]-600))+",";
				vlan[3]=vlan[3]+((svlan[0]-400)+"-"+(svlan[1]-400))+",";
			}
		}
		vlan[0]=vlan[0].substring(0, vlan[0].length()-1);
		vlan[1]=vlan[1].substring(0, vlan[1].length()-1);
		vlan[2]=vlan[2].substring(0, vlan[2].length()-1);
		vlan[3]=vlan[3].substring(0, vlan[3].length()-1);
		return vlan;
	}
}
